<template>
	<view class="wrap">
		<view class="search-box pb-0">
			<u-search placeholder="请输入" v-model="searchData.name" @search="onSearch" :showAction="false" />
		</view>
		<view class="bg-white">
			<u-tabs 
				:list="tags" 
				:current="selectTag" 
				@click="sectionChange" 
				:scrollable="false" 
				lineWidth="60"
				lineColor="#e54d42"
				:activeStyle="{color:'#e54d42'}"
			/>
		</view>
		<view class="my-list">
			<u-list :height="swiperHeight" @scrolltolower="scrolltolower" v-if="dataList.length > 0">
				<u-list-item v-for="(item, index) in dataList" :key="item.id">						  
					<view class="item">
						<view class="flex">
							<view class="shrink0 mr-20">
								<u-avatar :src="item.avatarImage || '/static/logo.png'" shape="circle" />
							</view>
							<view class="w-100 flex justify-between">
								<view class="">
									<view>
										<text class="fsize-30">{{item.nickName}}</text>
										<text class="fsize-24 line-gray">【{{item.id}}】</text>
									</view>
									<view class="fsize-24 line-gray">地区:--</view>
								</view>
								<view @click.stop>
									<uni-icons custom-prefix="iconfont" type="icon-phone" color="#81c66d" size="34" @click="phoneCall(item.mobile)"/>
								</view>
							</view>
						</view>
						<view class="flex justify-between align-center fsize-24 line-gray mt-30">
							<view class="">
								<text>帮推<text class="line-blue">{{item.childNum}}</text>人</text>
								<text class="ml-10">· 共消费</text>
								<text class="line-red">￥{{item.totalConsume}}</text>
							</view>
							<text>{{item.createTime}}</text>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				tags: [
					{ name: '直推客户', value: 0 }, 
					{ name: '间推客户', value: 1 },
				],
				selectTag: 0,
				dataList: [],
				searchData: {
					name:'',
					staffId: '',
					listType: 0,
					page: 1,
					limit: 20
				},
				loadmore:{
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
			}
		},
		onLoad(option) {
			this.searchData.inviteStaffId = option.id
			this.onSearch()
			uni.setNavigationBarTitle({ title:`${option.userName}的客户列表` })
		},
		methods: {
			phoneCall(num){
				uni.makePhoneCall({ phoneNumber: num })
			},
			sectionChange(e) {
				if (this.selectTag === e.index) return
				this.selectTag = e.index
				this.searchData.listType = e.value
				this.onSearch()
				// this.dataList = []
				// this.getData()
			},
			onSearch() {
				this.dataList = []
				this.searchData.page = 1
				this.getData()
			},
			getData(){
				this.$reqPost('GetShareholderUsersPageList',this.searchData).then(res=>{
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore'
						this.searchData.page++
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore'
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getData()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
page {
	background-color: #f8f8f8;
}
.search {
    padding: 10px 10px 0;
    background: #f8f8f8;
    height: 40px;
}
.tag{ 
	margin-left: 20rpx;
	font-size: 18rpx;
	font-weight: normal;
}
.btn-plus {
	position: absolute;
	bottom: 50rpx;
	right: 50rpx;
	z-index: 1;
	opacity: 0.6;
}
.btn-plus:hover {
	opacity: 1;
}
.my-list{ padding: 0 5px;}
.subtitleinline{ 
	display: inline-block; 
	padding-right: 10px; 
	font-size: 14px;
}
.vertical-center{ 
	display: flex;
	justify-content: center;
	align-items: center;
}
.avatar{ margin-right: 30rpx;}
</style>
